require(magrittr)
require(dplyr)
require(tidyr)
require(ComplexHeatmap)
require(tidyverse)
require(pheatmap)
require(corrplot)
require(circlize)
require(GGally)
require(linkET)
require(ggraph)
require(ggpubr)
require(ggside)
require(ggcor)
require(stringi)

rm(list=ls())#clear Global Environment
setwd('./Fig.1F')
liqid_mumian<-read.csv(file="metablitics_mumian.csv" ,row.names=1)

liqid_mumian%>%
  dplyr::select(-name)%>%
  tidyr::gather(treatment,value,-Compound_ID)%>%
  dplyr::mutate(repetition=treatment%>%
                  stri_extract(regex="[0-9]+"))%>%
  dplyr::mutate(treatment=treatment%>%
                  stri_replace("",regex="[0-9]+"))%>%
  dplyr::mutate(variable=paste(Compound_ID,repetition,sep=""))%>%
  dplyr::select(variable,treatment,value)%>%
  tidyr::spread(treatment,value)%>%
  dplyr::select(variable,Y,OY,OR,R,DR)->ggData

par(bg = "#fdfdfd")
ggData%>%
  ggpairs(par(bg = "#fdfdfd"),
    columns=2:ncol(ggData),
    upper=list(continuous=wrap("cor",colour="#87C55F")),
    lower=list(continuous=wrap("points",colour="#FE88B1",alpha=0.3)),
    diag=list(continuous=wrap("barDiag",fill="#f89c74",alpha=0.3))
  )

my_palette<-colorRampPalette(c("#87c55f","white","#fe88b1"))(50)
ggData%>%
  magrittr::extract(,2:ncol(ggData))%>%
  cor%>%
  corrplot.mixed(lower.col=my_palette,
                 upper.col=my_palette,tl.cex=0.8)

head(liqid_mumian)
names(ggData)
df<-ggData[,2:6]
names(df)
testRes = cor.mtest(df, method="pearson",conf.level = 0.95)
corrplot(ggData, method = "color", col = addcol(100), 
         tl.col = "black", tl.cex = 0.8, tl.srt = 45,tl.pos = "lt",
         p.mat = testRes$p, diag = T, type = 'upper',
         sig.level = c(0.001, 0.01, 0.05), pch.cex = 1.2,
         insig = 'label_sig', pch.col = 'grey20', order = 'AOE')
corrplot(tdc, method = "number", type = "lower",col = addcol(100), 
         tl.col = "n", tl.cex = 0.8, tl.pos = "n",order = 'AOE',
         add = T)




testRes = cor.mtest(ggData, method="pearson",conf.level = 0.95)
corrplot(tdc, method = "color", col = addcol(100), 
         tl.col = "black", tl.cex = 0.8, tl.srt = 45,tl.pos = "lt",
         p.mat = testRes$p, diag = T, type = 'upper',
         sig.level = c(0.001, 0.01, 0.05), pch.cex = 1.2,
         insig = 'label_sig', pch.col = 'grey20', order = 'AOE')
corrplot(tdc, method = "number", type = "lower",col = addcol(100), 
         tl.col = "n", tl.cex = 0.8, tl.pos = "n",order = 'AOE',
         add = T)


